<template>
	<view>
		<view class="uni-navbar">
			<view class="uni-navbar__content" :class="{'uni-navbar--fixed': !!fixed,'uni-navbar--shadow':!!border,'uni-navbar--border':!!border}" :style="{'background-color':backgroundColor}">
				<uni-status-bar v-if="statusBar"></uni-status-bar>
				<view class="uni-navbar__header" :style="{color:color}">
					<view class="uni-navbar__header-btns" @tap="onClickLeft" style="width:15px;">
						<view v-if="showBack" class="nav-back">
						</view>
						<view v-if="leftIcon.length" style="width: 30px;text-align: right;" >
							<uniIcon :type="leftIcon" :color="color" size="24"></uniIcon>
						</view>
						<view v-if="leftText.length" class="uni-navbar-btn-text" :class="{'uni-navbar-btn-icon-left':!leftIcon.length}">{{leftText}}</view>
						<slot name="left"></slot>
					</view>
					<view class="uni-navbar__header-container">
						<view v-if="title.length" class="uni-navbar__header-container-inner">{{title}}</view>
						<!-- 标题插槽 -->
						<slot></slot>
					</view>
					<view class="uni-navbar__header-btns" @tap="onClickRight">
						<view v-if="rightIcon.length">
							<uniIcon :type="rightIcon" :color="color" size="24"></uniIcon>
						</view>
						<!-- 优先显示图标 -->
						<view v-if="rightText.length&&!rightIcon.length" class="uni-navbar-btn-text">{{rightText}}</view>
						<slot name="right"></slot>
					</view>
				</view>
			</view>
			<view class="uni-navbar__placeholder" v-if="fixed">
				<uni-status-bar v-if="statusBar"></uni-status-bar>
				<view class="uni-navbar__placeholder-view"></view>
			</view>
		</view>
		<view style="height:44px;"></view>
	</view>
</template>

<script>
	import uniStatusBar from '../uni-status-bar/uni-status-bar.vue'
	import uniIcon from '../uni-icon/uni-icon.vue'

	export default {
		name: 'uni-nav-bar',
		components: {
			uniStatusBar,
			uniIcon
		},
		props: {
			showBack: {
				type: [Boolean],
				default: true
			},
			title: {
				type: String,
				default: ''
			},
			leftText: {
				type: String,
				default: ''
			},
			rightText: {
				type: String,
				default: ''
			},
			leftImg: {
				type: String,
				default: ''
			},
			leftIcon: {
				type: String,
				default: ''
			},
			rightIcon: {
				type: String,
				default: ''
			},
			fixed: {
				type: [Boolean, String],
				default: false
			},
			color: {
				type: String,
				default: '#ffffff'
			},
			backgroundColor: {
				type: String,
				default: '#FFFFFF'
			},
			statusBar: {
				type: [Boolean, String],
				default: false
			},
			shadow: {
				type: [String, Boolean],
				default: false
			},
			border: {
				type: [String, Boolean],
				default: false
			}
		},
		methods: {
			onClickLeft() {
				uni.navigateBack({
					delta: 1,
					animationType: 'pop-out',
				    animationDuration: 300,
				});
				//this.$emit('click-left')
			},
			onClickRight() {
				this.$emit('click-right')
			}
		}
	}
</script>

<style>
	@charset "UTF-8";

    .uni-navbar{
		position: fixed;
		top: 0px;
		left: 0px;
		right: 0px;
	}
	.uni-navbar__content {
		display: block;
		position: relative;
		width: 100%;
		background-color: #fff;
		overflow: hidden
	}

	.uni-navbar__content view {
		line-height: 44px
	}

	.uni-navbar__header {
		display: flex;
		flex-direction: row;
		width: 100%;
		height: 44px;
		line-height: 44px;
		background: linear-gradient(90deg, #FF6590 0%, #FF6A6A 100%);
		color: #FFFFFF;
		font-size: 16px
	}

	.uni-navbar__header-btns {
		/* display: inline-flex; */
		flex-wrap: nowrap;
		flex-shrink: 0;
		width: 60upx;
	}

	.uni-navbar__header-btns:first-child {
		padding-left: 0;
		margin-left: 30upx
	}

	.uni-navbar__header-btns:last-child {
		margin-right: 30upx;
		text-align: right;
	}

	.uni-navbar__header-container {
		width: 100%;
		margin: 0 10upx
	}

	.uni-navbar__header-container-inner {
		font-size: 30upx;
		text-align: center;
	}

	.uni-navbar__placeholder-view {
		height: 44px
	}

	.uni-navbar--fixed {
		position: fixed;
		z-index: 998
	}

	.uni-navbar--shadow {
		box-shadow: 0 1px 6px #ccc
	}

	.uni-navbar--border:after {
		position: absolute;
		z-index: 3;
		bottom: 0;
		left: 0;
		right: 0;
		height: 1px;
		content: '';
		-webkit-transform: scaleY(.5);
		transform: scaleY(.5);
		background-color: #c8c7cc
	}
	
	.nav-back{
	    content: " ";
	    display: inline-block;
	    height: 12px;
	    width: 12px;
	    border-width: 1px 1px 0 0;
	    border-color: #FFFFFF;
	    border-style: solid;
	    -webkit-transform: matrix(-0.71, 0.71, 0.71, 0.71, 0, 0);
	    transform: matrix(-0.71, 0.71, 0.71, 0.71, 0, 0);
	    position: absolute;
	    top: 16px;
	    left: 30upx;
	}
</style>